Approximating data with exponentials using Matlab

The polynomial data fitting using the Matlab functions polyfit and polyval is very convenient. But what if the appropriate fitting function is not a polynomial? Very often the fitting function is an exponential or a power law. Matlab does not have functions that fit data to these mathematical functions. However, a little mathematical manipulation of the data points enables you to use the same polynomial functions to fit your data.

Suppose that you have a set of data points that you expect to follow an exponential function trend. Thus you would like to use as the approximating function such that the data roughly follows the relationship where a and c are parameters that are determined by the least squares method to come close to the data points.

To accomplish this, first take the logarithm of each side of the equation

Now define new variables: and . Then you can rewrite the equation as

From this equation you can see that the data values a linear trend. Thus you can use a linear function to fit the data pairs and this is equivalent to using an exponential function to fit the original data . The only change you need to make is taking the logarithm of the values before applying the data fitting algorithm.

Similarly, if the data pairs are expected to follow a power law trend then you would like to use an approximating function of the form where a and c are parameters determined by the least squares method to come close to the data points. Once again we transform the fitting equation in the following way.

Define new variables: , and and substitute to get

This is a linear relationship between the new data values . Thus you can use a linear function to fit the data pairs and this is equivalent to using a power law function to fit the original data . The changes you need to make are taking the logarithm of both the and data values before applying the data fitting algorithm.